<?php

namespace App\Http\Controllers\VideoAdmin;

use App\Http\Controllers\Admin\BaseController;
use App\Models\video\CommentModel;
use App\Models\video\DynamicModel;
use App\Models\video\ReplyModel;
use App\Models\video\VideoUserModel;
use App\Models\video\VodVideoModel;
use Illuminate\Http\Request;

class CommentController extends BaseController
{
    public function __construct(Request $request)
    {
        parent::__construct($request);
    }

    // 获取评论列表
    public function getCommentList(Request $request){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        $page = $request->page ?: 1;
        $pageSize = $request->pageSize ?: 10;
        if($request->searchText){

        }
        $filter = [["mall_id", "=", $request->mallData["id"]]];
        $data = CommentModel::getList("id,user_id,belong_id,contents,type,discuss_num,praise_num,tread_num,status,create_time", $filter, $page, $pageSize);
        foreach ($data["list"] as &$item){
            if(empty($havingData[$item["userId"]])){
                $havingData[$item["userId"]] = VideoUserModel::getFields("avatar,nickname", ["id" => $item["userId"]]);
            }
            $item["userName"] = isset($havingData[$item["userId"]]["nickname"]) ? $havingData[$item["userId"]]["nickname"] : "";
            $item["userAvatar"] = isset($havingData[$item["userId"]]["avatar"]) ? $havingData[$item["userId"]]["avatar"] : "";
            $item["replyCount"] = ReplyModel::getCount(["comment_id" => $item["id"]]);
//            if($item["type"] == '1'){ // 1视频，2课程，3动态
//                if(empty($temp[$item["type"]][$item["belongId"]]))
//                    $temp[$item["type"]][$item["belongId"]] = VodVideoModel::getFields("title", ["id" => $item["belongId"]], true, false);
//                $item["title"] = !empty($temp[$item["type"]][$item["belongId"]]["title"]) ? $temp[$item["type"]][$item["belongId"]]["title"] : "";
//            }elseif($item["type"] == '2'){
//                $item["title"] = !empty($temp[$item["type"]][$item["belongId"]]["title"]) ? $temp[$item["type"]][$item["belongId"]]["title"] : "";
//            }else{
//                if(empty($temp[$item["type"]][$item["belongId"]]))
//                    $temp[$item["type"]][$item["belongId"]] = DynamicModel::getFields("contents", ["id" => $item["belongId"]], true, false);
//                $item["title"] = !empty($temp[$item["type"]][$item["belongId"]]["contents"]) ? $temp[$item["type"]][$item["belongId"]]["contents"] : "";
//            }
        }
        $this->returnData["data"] = $data;
        return $this->return_result($this->returnData);
    }

    public function getCommentDetail(){

    }

    // 删除评论
    public function delComment(Request $request){
        if($this->returnData["code"] !== 0){
            return $this->return_result($this->returnData);
        }
        CommentModel::delByFilter(["id" => $request->id]);
        return $this->return_result($this->returnData);
    }
}
